package com.dzxcqmxm.servlet.photo;

import com.dzxcqmxm.Dao.PhotoDao;
import com.dzxcqmxm.Dao.impl.PhotoDaoImpl;
import com.dzxcqmxm.JB.Photo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * 这个是给首页用的
 * 用于执行照片名查找的那个方法
 */
@WebServlet("/photoFindbyAlbumUrlServlet")
public class photoFindbyAlbumUrlServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PhotoDao photoDao = new PhotoDaoImpl();
        Photo photo = new Photo();

        ArrayList<Photo> photoArrayList = new ArrayList<Photo>();
        /**
         * 获取链接上的参数
         */
        String AlbumUrl = request.getParameter("AlbumUrl");


        try {
            photoArrayList = photoDao.photoFindbyAlbumUrl(AlbumUrl);
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("打印一下用相册名查照片的photoArrayList"+photoArrayList);

        //session会话对象可以数据共享于一次会话
        request.getSession().setAttribute("photoArrayList", photoArrayList);

        System.out.println("验证一下我刚设定好的session对象："+request.getSession().getAttribute("photoArrayList"));
        //request.getSession().setAttribute("XTXCName", XTXCName);

        response.sendRedirect("/dzxc/YongHu/yhPhoto/yhDisplayPhoto.jsp");

    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            doPost(request, response);
        } catch (ServletException e) {
            e.printStackTrace();
        }
    }
}
